import request from '@/utils/request'
import type { ApiResponse } from './components/ApiResponse'
import type { AddressType, AddAddressType } from './components/addressType'

interface Id {
  id: string
}

// 获取收货地址列表
export const getAddressListApi = () => {
  return request.get<ApiResponse<[AddressType]>>('/member/address')
}

// 添加收货地址
export const addAddressApi = (data: AddAddressType) => {
  return request.post<ApiResponse<Id>>('/member/address', data)
}

// 修改收货地址
export const updateAddressApi = (info: AddressType) => {
  return request.put(`/member/address/${info.id}`, {
    data: { info },
  })
}

// 删除收货地址
export const deleteAddressApi = (id: string) => {
  return request.delete<ApiResponse<Id>>(`/member/address/${id}`)
}
